package com.yz.lzq.liwushuo.ui.webview.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yz.lzq.liwushuo.R;
import com.yz.lzq.liwushuo.ui.modules.home.boutique.gridview.creditstopic.CreditsTopicContract;
import com.yz.lzq.liwushuo.ui.modules.home.boutique.gridview.creditstopic.CreditsTopicPresenter;

import butterknife.Bind;
import butterknife.ButterKnife;

public class HomeWebContentActivity extends AppCompatActivity implements View.OnClickListener, CreditsTopicContract.CreditsTopicViewInterface {

    @Bind(R.id.imageView_content_home_back)
    ImageView imageViewContentHomeBack;
    @Bind(R.id.textView_webView_tittle)
    TextView textViewWebViewTittle;
    @Bind(R.id.TextView_content_home_back)
    TextView TextViewContentHomeBack;
    @Bind(R.id.webView_showContent)
    WebView webViewShowContent;
    @Bind(R.id.textView_content_home_likeCount)
    TextView textViewContentHomeLikeCount;
    @Bind(R.id.textView_content_home_shareCount)
    TextView textViewContentHomeShareCount;
    @Bind(R.id.textView_content_home_commentCount)
    TextView textViewContentHomeCommentCount;
    @Bind(R.id.activity_show_content)
    LinearLayout activityShowContent;
    @Bind(R.id.linearLayout_content_home_likeCount)
    LinearLayout linearLayoutContentHomeLikeCount;
    @Bind(R.id.linearLayout_content_home_shareCount)
    LinearLayout linearLayoutContentHomeShareCount;
    @Bind(R.id.linearLayout_content_home_commentCount)
    LinearLayout linearLayoutContentHomeCommentCount;
    private CreditsTopicPresenter presenter = null;
    private int itemId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_home_recycler);
        ButterKnife.bind(this);
        initView();
        presenter = new CreditsTopicPresenter(this);
        presenter.showGetNetWorkData();
        imageViewContentHomeBack.setOnClickListener(this);

    }

    private void initView() {
        Intent intent = getIntent();
        itemId = intent.getIntExtra("itemId", 0);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.imageView_content_home_back:
                finish();
                break;
        }
    }

    @Override
    public void getWebViewUrl(String url) {
        showWebView(url);
    }

    private void showWebView(String url) {
        webViewShowContent.getSettings().setJavaScriptEnabled(true);
        webViewShowContent.loadUrl(url);
        webViewShowContent.setWebViewClient(new WebViewClient() {
            //强制使用web view加载网页
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    public String getCurrentItemId() {
        return "";
    }

    @Override
    public int getItemId() {
        return itemId;
    }

    @Override
    public void getLikeCount(String likeCount) {
        textViewContentHomeLikeCount.setText(likeCount);
    }

    @Override
    public void getLShareCount(String shareCount) {
        textViewContentHomeShareCount.setText(shareCount);
    }

    @Override
    public void getCommenCount(String commenCount) {
        textViewContentHomeCommentCount.setText(commenCount);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
